const OSS = require('ali-oss');
const STS = OSS.STS;

const sts = new STS({
  accessKeyId: 'LTAI4G2Yo3TGvcjDPdDuuLL8',
  accessKeySecret: 'Jujx0DsIEgomcKPYLF3bDTX7VWJ2Ir'
});

async function getCredential(req, res, next) {
    console.log('我进来了')
  try {
    const { credentials } = await sts.assumeRole(
      'acs:ram::1545512553179923:role/sun142725',  // role arn
      null, // policy
      15 * 60, // expiration
      'web-client' // session name
    );
    req.result = credentials;
    next(credentials);
  } catch (err) {
    next(err);
  }
}
// cn-beijing
module.exports = getCredential